/*******************************************************************************
 * Copyright 2011, 2012 Chris Banes.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.interesting.client.support.pulltorefresh;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.interesting.R;
import com.interesting.base.core.BaseActivity;

//TODO 是否需要
public class PullToRefreshListActivity extends BaseActivity {
	protected View footerView;
	protected PullToRefreshListView pullToRefreshListView;
	protected TextView empty;
	protected ProgressBar progressBar;


	protected boolean isFooterDisplay;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview_layout);
		empty = (TextView) findViewById(R.id.empty);
		progressBar = (ProgressBar) findViewById(R.id.progressbar);
		pullToRefreshListView = (PullToRefreshListView) findViewById(R.id.listView);
		LayoutInflater inflater = LayoutInflater.from(PullToRefreshListActivity.this);
		footerView = inflater.inflate(R.layout.listview_footer_layout, null);
		getListView().addFooterView(footerView);
		getListView().setHeaderDividersEnabled(false);
		dismissFooterView();
	}

	protected ListView getListView() {
		return pullToRefreshListView.getRefreshableView();
	}

	protected void show() {
		progressBar.setVisibility(View.GONE);
		pullToRefreshListView.setVisibility(View.VISIBLE);
	}

	protected void hide() {
		progressBar.setVisibility(View.VISIBLE);
		pullToRefreshListView.setVisibility(View.GONE);
	}

	protected void showFooterView() {
		TextView tv = ((TextView) footerView.findViewById(R.id.listview_footer));
		tv.setVisibility(View.VISIBLE);
		tv.setText(getString(R.string.loading));
		View view = footerView.findViewById(R.id.refresh);
		view.setVisibility(View.VISIBLE);
		view.startAnimation(AnimationUtils.loadAnimation(PullToRefreshListActivity.this, R.anim.refresh));
		isFooterDisplay = true;
	}

	protected void dismissFooterView() {
		footerView.findViewById(R.id.refresh).setVisibility(View.GONE);
		footerView.findViewById(R.id.refresh).clearAnimation();
		footerView.findViewById(R.id.listview_footer).setVisibility(View.GONE);
		isFooterDisplay = false;
	}
}